
package ProOF.apl.problems.real.operators;

import ProOF.apl.problems.real.RealCodification;
import ProOF.apl.problems.real.RealProblem;
import ProOF.com.LinkerParameters;
import ProOF.gen.operator.oMutation;

/**
 *
 * @author Hossomi
 */
public class RealMutSmallShake extends oMutation<RealProblem, RealCodification> {
    private double magnitude;
    private double vol;
    
    @Override
    public String name() {
        return "SmallShake";
    }

    @Override
    public void parameters(LinkerParameters win) throws Exception {
        magnitude = win.Dbl("SmallShake magnitude", 0.05, 0, 1);
        vol = win.Dbl("SmallShake volatility", 0.5, 0, 1);
    }
    
    @Override
    public void mutation(RealProblem prob, RealCodification ind) throws Exception {
        double rng, min, max;
        for (int i = 0; i < prob.func.dimension(); i++) {
        	if (prob.rmd.nextDouble() < vol) {
        		rng = 0.5*magnitude * (prob.func.max(i) - prob.func.min(i));
        		min = Math.max( ind.x[i] - rng, prob.func.min(i) );
        		max = Math.min( ind.x[i] + rng, prob.func.max(i) );
        		ind.x[i] = prob.rmd.nextDouble(min, max);
        	}
        }
        prob.func.adjust(ind.x);
    }

}
